package com.imooc.config;

import com.imooc.job.MyJob;
import org.quartz.*;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail getMyJobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myjob1", "group1")
                .storeDurably()
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger getTrigger() {
        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .startNow()
                .withIdentity("trigger1", "group1")
                .forJob(getMyJobDetail())
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(5)
                        .repeatForever()
                ).build();
        return trigger;
    }
}
